package cep.web.media.controller;

import cep.model.dao.CoreDao;
import cep.web.media.beans.NewsListBean;
import cep.web.person.mapper.PersonMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * User: golovin
 * Date: 23.06.13
 * Time: 17:40
 */
@Controller
public class NewsController {
    @Autowired
    private NewsListBean newsListBean;
    @Autowired
    @Qualifier("commonDaoImplMock")
    private CoreDao coreDao;
    @Autowired
    private PersonMapper personMapper;

    private final Log LOG = LogFactory.getLog(getClass());

    @RequestMapping(value = "/")
    public String handleString() {
        LOG.info("Returning Main news_list view ");
        return "redirect:/news_list";
    }

    @RequestMapping(value = "/news_list")
    public ModelAndView handleRequest() {
        LOG.info("Returning news_list view ");
        ModelAndView mvc = new ModelAndView("news_list");

        personMapper.mapNews(newsListBean.getNewsList());
        LOG.info("count news " + newsListBean.getNewsList().size());
        mvc.addObject("newsListBean", newsListBean);
        return mvc;
    }
}
